package jp.co.jbuy.action;

import javax.servlet.http.HttpServletRequest;

import jp.co.jbuy.action.product.ProductDetailAction;
import jp.co.jbuy.action.search.SearchAction;
import jp.co.jbuy.action.user.LoginAction;
import jp.co.jbuy.action.user.RegistAction;
import jp.co.jbuy.action.user.ShowLoginViewAction;
import jp.co.jbuy.action.user.ShowRegistViewAction;

public class ActionManager {

	public BaseAction createPage(HttpServletRequest req) {

		BaseAction instance = createPageCore(req);
		return instance;
	}

	private BaseAction createPageCore(HttpServletRequest req) {

		String page = req.getParameter("action");

		if (page == null) {
			return new IndexPageAction();
		}
		else if (page.equals(SearchAction.PAGE_ID)) {
			return new SearchAction();
		}
		else if (page.equals(ProductDetailAction.PAGE_ID)) {
			return new ProductDetailAction();
		}
		else if (page.equals(ShowLoginViewAction.PAGE_ID)) {
			return new ShowLoginViewAction();
		}
		else if (page.equals(ShowRegistViewAction.PAGE_ID)) {
			return new ShowRegistViewAction();
		}
		else if (page.equals(LoginAction.PAGE_ID)) {
			return new LoginAction();
		}
		else if (page.equals(RegistAction.PAGE_ID)) {
			return new RegistAction();
		}
		return new IndexPageAction();
	}
}